﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
using System.Reflection;

namespace Marking.Dashboard.Infrastructures
{
    public static class ReportHelper
    {
        public static void Show(string url, object args)
        {
            if (HtmlPage.IsPopupWindowAllowed)
            {
                if (args != null)
                {
                    foreach (var property in args.GetType().GetProperties())
                    {
                        if (url.Contains("?"))
                        {
                            url += "&";
                        }
                        else
                        {
                            url += "?";
                        }

                        url += string.Format("{0}={1}", property.Name, HttpUtility.UrlEncode(property.GetValue(args, null).ToString()));
                    }
                }

                var options = new HtmlPopupWindowOptions();
                options.Width = 1000;
                options.Height = 700;
                options.Resizeable = true;

                var currentUri = HtmlPage.Document.DocumentUri;
                url = string.Format("{0}://{1}:{2}{3}", currentUri.Scheme, currentUri.Host, currentUri.Port, url);

                HtmlPage.PopupWindow(new Uri(url), null, options);
            }
        }
    }
}
